package fr.ttalbot.flex.effects.instances
{
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import mx.effects.EffectInstance;
	
	public class ArcInstance extends EffectInstance
	{
		public var xBy: Number;
		public var yBy: Number;
		public var xTo: Number;
		public var yTo: Number;
		public var xFrom: Number;
		public var yFrom: Number;
		public var radius: int;
		public var angle: Number;
		
		private var timer: Timer;
		private var teta: int;
		
		// ***************************************************************** //
		// ************************** CONSTRUCTOR ************************** //
		// ***************************************************************** //
		
		public function ArcInstance(target: Object) {
			super(target);
			xFrom = target.x;
			yFrom = target.y;
			timer =  new Timer(10);
			timer.addEventListener(TimerEvent.TIMER, handle_timer)
		}
		
		override public function play(): void {
			super.play();
			timer.start();
		}
		
		private function handle_timer(event: TimerEvent): void {
			this.target.x = radius*Math.cos((Math.PI*teta)/180) - (xFrom+radius);
			this.target.y = radius*Math.sin((Math.PI*teta)/180) - (yFrom);
			this.target.rotation = teta;
			teta++;
			if (teta == angle)
				timer.stop();
		}
	}
}